<html lang="zh-cn">
  <head>
    <meta charset="utf-8">
    <script src="place.js"></script>
    <script src="process.js"></script>
   <script src="jquery-min.js"></script>
	<script src="ns.js"></script>
	<style>
		.other {
			color:red;
			font-weight:700;
		}
	</style>
  </head>
  <body>
  <h1>Process</h1>
  类型定义:<br>
  <textarea id= "usertypes" style="height:120px;">tvm
问题处理
维护
mis
接口
非接升级
培训
巡检
密码键盘
清分
单边账
程序更新
单边账
查账</textarea><br>
<input type="button" onclick="ana()" value="分析">
  <div id="list">
  </div>
  
  <script type="text/javascript"> 
  

function arrayremove(a, dx) {
	if (isNaN(dx) || dx > a.length) {
		return false;
	}
	var tmp = [];
	for (var i = 0, n = 0; i < a.length; i++) {
		if (a[i] != a[dx]) {
			tmp.push(a[i]);
		}
	}
	return tmp;
}

function ana() {
	var types = $("#usertypes").val().split('\n');
	var counter = {};
	var analyze = {};
	for (var index in ns) {
		counter[ns[index]] = counter[ns[index]] + 1 || 1;
	}

	var totaltype = {};
	for (var index in datasrc) {
		var times = undefined;
		var src = datasrc[index];
		if (analyze[src])
			times = analyze[src].times;
		var an = {
			times: times + 1 || 1
		};
		for (var n in counter) {
			if (src.indexOf(n) != -1)
				an['place'] = n;
		}
		var keep = true;
		var process = [];
		var tmptypes = types;
		var marked = false;
		var other = false;
		for (var t in tmptypes) {
			if (src.indexOf(types[t]) != -1) {
				process.push(types[t]);
				if (!marked) {
					totaltype[types[t]] = totaltype[types[t]] + 1 || 1;
					marked = true;
				}
			}
		}
		if (!marked) {
			process.push('其他');
			totaltype['其他'] = totaltype['其他'] + 1 || 1;
			an['other'] = true;
		}

		if (process.length)
			an['type'] = process;

		analyze[src] = an;
	}
	var l = "<table><tr><td>序列</td><td>处理事件</td><td>区域</td><td>处理内容</td><td>次数</td></tr>";
	var id = 0;
	var keys = [];
	for (var k in analyze) {
		keys.push(k);
	}
	keys = keys.sort();
	var anatmp = [];
	for (var k in keys) {
		var val = analyze[keys[k]];
		var v = {
			desc: keys[k],
			src: val
		};
		anatmp.push(v);
	}

	for (var k in anatmp) {
		var v = anatmp[k];
		if (v.src.place)
			l += "<tr><td>" + id++ + "</td><td>" + v.desc + "</td><td>" + v.src.place + "</td><td" + (v.src.other?" class='other'":"")+ ">" + (v.src.type || ['']).join(',') + "</td><td>" + v.src.times + "</td></tr>";
	}
	$("#list").html(l + "</table>");
	l = "<table><tr><td>地区</td><td>处理计数(件)</td></tr>";
	keys = [];
	for (var k in counter) {
		keys.push(k);
	}
	keys = keys.sort();
	var tmpcounter = {};
	for (var k in keys) {
		var key = keys[k];
		tmpcounter[key] = counter[key];
	}
	for (var k in tmpcounter) {
		var v = tmpcounter[k];
		l += "<tr><td>" + k + "</td><td>" + v + "</td></tr>";
	}
	l += "</table>";
	$("#list").html($("#list").html() + l);

	l = "<table><td>事件</td><td>件次</td>";
	for (var k in totaltype) {
		l += "<tr><td>" + k + "</td><td>" + totaltype[k] + "</td><tr>";
	}
	l += "</table>";
	$("#list").html($("#list").html() + l);
}

  </script>
  </body>
</html>